package com.example.smart_park2211a

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.example.component_dome.R
import com.example.component_dome.databinding.ActivityBootstrapBinding
import com.example.lib_base.mvvm.BaseViewActivity
import android.view.View
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.tencent.bugly.crashreport.CrashReport
import com.youth.banner.Banner
import com.youth.banner.adapter.BannerImageAdapter
import com.youth.banner.holder.BannerImageHolder
import com.youth.banner.listener.OnPageChangeListener
@Route(path = "/app/BootstrapActivity")
class BootstrapActivity : BaseViewActivity<ActivityBootstrapBinding>() {
    override fun initData() {
    }
    override fun initView() {
        // Banner数据
        val bannerList = listOf(
            R.drawable.guide_img1,
            R.drawable.guide_img2,
            R.drawable.guide_img3
        )
        val titleList = listOf(
            "智慧园区 智享生活",
            "高效管理 便捷服务",
            "安全守护 贴心体验"
        )
        val descList = listOf(
            "打造智能化园区管理体系，提供便捷的一站" +
                    "式服务体验",
            "高效的物业管理，智能停车，访客无忧",
            "多重安全保障，守护您的每一天"
        )
        // 设置Banner
        binding.banner.apply {
            setAdapter(object : BannerImageAdapter<Int>(bannerList) {
                override fun onBindView(holder: BannerImageHolder, data: Int, position: Int, size: Int) {
                    holder.imageView.setImageResource(data)
                }
            })
            addOnPageChangeListener(object : OnPageChangeListener {
                override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {}
                override fun onPageSelected(position: Int) {
                    // 标题和描述切换
                    binding.tvTitle.text = titleList[position]
                    binding.tvDesc.text = descList[position]
                    // 立即体验按钮只在第三页显示
                    binding.btnStart.visibility = if (position == 2) View.VISIBLE else View.GONE
                }
                override fun onPageScrollStateChanged(state: Int) {}
            })
        }
        // 跳过按钮
        binding.tvSkip.setOnClickListener {
            // 跳转到主页面
            ARouter.getInstance().build("/main/MainActivity").navigation()
            CrashReport.testJavaCrash();
            finish()
        }
        // 立即体验按钮
        binding.btnStart.setOnClickListener {
            // 跳转到主页面
            ARouter.getInstance().build("/main/MainActivity").navigation()
            finish()
        }
        // 初始化时显示第一页内容
        binding.tvTitle.text = titleList[0]
        binding.tvDesc.text = descList[0]
        binding.btnStart.visibility = View.GONE
    }
}